const Router = require('koa-router');
// 整数校验器
const {LikeValidator} = require('../../validators/validator')
const {Auth} = require('../../../middlewares/auth')
const {Favor} = require('../../models/Favor')
const { success } = require('../../lib/helper')

const router = new Router({
  prefix: '/v1/like'
})


// 点赞
router.post('/',  new Auth().m, async (ctx, next) => {
  // 支持别名
  const v = await new LikeValidator().validate(ctx, {
    id: 'art_id'
  })
  await Favor.like(v.get('body.art_id'), v.get('body.type'), ctx.auth.uid)
  success('点赞成功')
  // ctx.body = art
})

// 取消点赞
router.post('/cancel',  new Auth().m, async (ctx, next) => {
  // 支持别名
  const v = await new LikeValidator().validate(ctx, {
    id: 'art_id'
  })
  await Favor.disLike(v.get('body.art_id'), v.get('body.type'), ctx.auth.uid)
  success('取消点赞成功')
  // ctx.body = art
})
module.exports= router